function eraseOverlapIntervals(intervals) {
    if (intervals.length === 0) return 0

    // 按区间的结束时间进行排序
    intervals.sort((a, b) => a[1] - b[1])

    let count = 0
    let end = -Infinity

    for (const [start, finish] of intervals) {
       if (start >= end) {
          // 当前区间可以保留，更新结束时间
          end = finish
       } else {
          // 当前区间与上一个区间重叠，需要移除
          count++
       }
    }

    return count
 }

 // 示例测试
 console.log(eraseOverlapIntervals([[1, 2], [2, 3], [3, 4], [1, 3]])) // 输出：1
 console.log(eraseOverlapIntervals([[1, 2], [1, 2], [1, 2]])) // 输出：2
 console.log(eraseOverlapIntervals([[1, 2], [2, 3]])) // 输出：0
 console.log(eraseOverlapIntervals([[1, 2], [1, 3], [2, 4], [3, 5]])) // 输出：1
 console.log(eraseOverlapIntervals([[0, 2], [1, 3], [2, 4], [3, 5], [4, 6]])) // 输出：2